(function($) {
    $.mask = {
        //Predefined character definitions
        definitions: {
            '9': "[0-9]",
            '1': "[1-9]",
            'a': "[A-Za-z]",
            'A': "[A-Z]",
            '*': "[A-Za-z0-9]"
        }
    };
})(jQuery);

function applyMask(selector, mask) {
    jq(selector).mask(mask, {
        placeholder: " "
    });
}

function toogle(selector) {
    var gBody = jq(selector).find('.g-cnt-body');

    if (gBody.is(":visible")) {
        jq(selector).find('.k-group-img').removeClass('k-group-img-open').addClass('k-group-img k-group-img-close');
        gBody.slideUp();
    } else {
        jq(selector).find('.k-group-img').removeClass('k-group-img-close').addClass('k-group-img k-group-img-open');
        gBody.slideDown();
    }
}

function show(selector) {
    var gBody = jq(selector).find('.g-cnt-body');

    if (!gBody.is(":visible")) {
        jq(selector).find('.k-group-img').removeClass('k-group-img-close').addClass('k-group-img-open');
        gBody.slideDown();
    }
}

function hide(selector) {
    var gBody = jq(selector).find('.g-cnt-body');

    if (gBody.is(":visible")) {
        jq(selector).find('.k-group-img').removeClass('k-group-img-open').addClass('k-group-img-close');
        gBody.slideUp();
    }
}

function toogle1(selector) {
    var gBody1 = jq(selector).find('.g-cnt-body1');
    var gBody2 = jq(selector).find('.g-cnt-body2');

    if (gBody1.is(":visible")) {        
        
        jq(selector).find('.k-group-img').removeClass('k-group-img-close').addClass('k-group-img-open');
        gBody1.slideUp();
        gBody2.slideDown();
    } else if (gBody2.is(":visible")) {
        jq(selector).find('.k-group-img').removeClass('k-group-img-open').addClass('k-group-img-close');
        gBody1.slideDown();
        gBody2.slideUp();
    } else {
        jq(selector).find('.k-group-img').removeClass('k-group-img-open').addClass('k-group-img-close');
        gBody1.slideDown();
        gBody2.slideUp();
    }
}

function toogle2(selector) {
    var gBody1 = jq(selector).find('.g-cnt-body1');    

    if (gBody1.is(":visible")) {                
        jq(selector).find('.k-group-img').removeClass('k-group-img-close').addClass('k-group-img-open');
        gBody1.slideUp();
     
    } else {
        jq(selector).find('.k-group-img').removeClass('k-group-img-open').addClass('k-group-img-close');
        gBody1.slideDown();        
    }
}

//
//zk.afterLoad("zul.db",function() {
//    zul.db.CalendarPop.prototype.onChange = function(evt) {
//        var date = this.getTime(),
//        db = this.parent,
//        fmt = db.getTimeFormat(),
//        oldDate = db.getValue();
//
//        if (oldDate)
//            date = new Date(date.getFullYear(), date.getMonth(),
//                date.getDate(), oldDate.getHours(),
//                oldDate.getMinutes(), oldDate.getSeconds(), oldDate.getMilliseconds());
//
//        if (fmt) {
//            var tm = db._tm,
//            time = tm.getValue();
//            date.setHours(time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds());
//        }
//
//        db.getInputNode().value = db.coerceToString_(date);
//        db.fire("onChange", evt.data);
//
//        if (this._view == 'day' && evt.data.shallClose !== false) {
//            this.close();
//            db._inplaceout = true;
//        }
//        evt.stop();
//    };
//});